package sort.test274;

import java.util.Arrays;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/19 11:25
 */
public class Solution1 {

    public int hIndex(int[] citations) {
        if (citations == null || citations.length == 0) return 0;
        Arrays.sort(citations);
        int n = citations.length;
        if (citations[n - 1] == 0) return 0;
        int l = 1, r = n;
        while (l < r) {
            int m = (l + r + 1) >> 1;
            if (citations[n - m] >= m) {
                l = m;
            } else {
                r = m - 1;
            }
        }
        return l;
    }
}
